import {
  Controller,
  Get,
  Post,
  Body,
  Put,
  Param,
  Delete,
} from '@nestjs/common';
import { StudentsService } from './students.service';
import { Student } from '@app/db/models/Student.model';
import { ApiTags, ApiOperation, ApiBody } from '@nestjs/swagger';

@Controller('students')
@ApiTags('学生证')
export class StudentsController {
  constructor(private studentsService: StudentsService) {}

  @Get()
  @ApiOperation({ summary: '学生证列表' })
  async findAll(): Promise<Student[]> {
    return this.studentsService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '获取单个学生证' })
  async findOne(@Param('id') stuId:string): Promise<Student> {
    return this.studentsService.findOne(stuId);
  }

  @Post()
  @ApiOperation({ summary: '新增学生证' })
  @ApiBody({ type: Student })
  async createStu(@Body('student') student: Student): Promise<Student> {
    return this.studentsService.createStu(student);
  }

  @Post('more')
  @ApiOperation({ summary: '插入学生证列表' })
  @ApiBody({ type: Student, isArray: true })
  async insertManyStu(
    @Body('students') students: Student[],
  ): Promise<Student[]> {
    return this.studentsService.insertMany(students);
  }

  @Put(':id')
  @ApiOperation({ summary: '修改学生证' })
  @ApiBody({ type: Student })
  async updateStu(@Body('student') student: Student, @Param('id') id: string) {
    return this.studentsService.updateStu(id, student);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除学生证' })
  async removeStu(@Param('id') id: string) {
    return this.studentsService.removeStu(id);
  }
}
